﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Win32;
namespace MVC4WPF.Automation
{
    /// <summary>
    /// Helper class that contains methods for managing templates used in automation.
    /// </summary>
    public static class TemplateManager
    {
        /// <summary>
        /// Helper method that will locate the templates folder that stores all MVC4WPF templates.
        /// </summary>
        /// <param name="version">The version of the templates to retrieve it will always be major minor version format. Example 1.0 or 1.1</param>
        /// <returns>The full path to the templates folder or null if no values were found, or the MVC4WPF registery entry is missing.</returns>
        public static string GetTemplateFilePath(string version)
        {
            string returnValue = null;
            try
            {
                RegistryKey MVCVersionKey = Registry.LocalMachine.OpenSubKey(string.Format(@"Software\MVC4WPF\V{0}",version.Trim()));

                if (MVCVersionKey != null)
                {
                    returnValue = MVCVersionKey.GetValue("TemplatePath", null) as string;
                }
            }
            catch(Exception)
            {
                return null;
            }

            return returnValue;
        }
    }
}
